import axios from 'axios'
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
// import Vue from 'vue'
// Vue.use(ElementUI);
let baseUrl= "http://ludir.cn:8888/api/private/v1/";
axios.defaults.baseURL =baseUrl;
// axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1/"
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

let AUTH_TOKEN = window.localStorage.getItem('myToken') || '';
// 请求拦截器
axios.interceptors.request.use(function (config) {
  if (config.url.includes('1106975712662')) {
    config.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/login';
    config.headers['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2Mzg5NTAwNjQsImV4cCI6MTYzOTAzNjQ2NH0.htOH1UMC4Ff5hxWxhsAyEvHSpvssfhK8woCYwO9s0I4';
  } else {
    config.baseURL = baseUrl;
    config.headers['Authorization'] = AUTH_TOKEN;
  }
  return config
}, function (error) {
  return Promise.reject(error)
})
// 相应拦截
axios.interceptors.response.use(function (response) {
    // let {meta:{status,msg}} =response.data;
    // if(status==200||201||204) this.$message.success(msg);
    // if(status==400||401||403) this.$message.warning(msg);
    // if(status==404||422||500) this.$message.error(msg);
    return response.data
}, function (error) {
    return Promise.reject(error)
})


// 导出方法
// 登录
export let getLogin=(params)=>axios.post('login',params)
// 获取用户列表
export let getUsers=(params)=>axios.get('users',{params})
// 改变用户状态
export let getChangeUserState=({id,mg_state})=>axios.put(`users/${id}/state/${mg_state}`)
// 添加用户
export let getAddUsers=(params)=>axios.post('users',params)
//编辑用户
export let getEditUsers=(params)=>axios.put(`users/${params.id}`,params)
//删除用户
export let getDelUsers=(params)=>axios.delete(`users/${params}`)
//获取角色列表
export let getRoles=(params)=>axios.get('roles')
//分配用户角色
export let getGrantRoles=(params)=>axios.put(`users/${params.id}/role`,params)
// 添加用户角色
export let getAddRoles=(params)=>axios.post('roles',params)
// 删除用户角色
export let getDelRoles=(params)=>axios.delete(`roles/${params}`)
//编辑提交角色
export let getEditRoles=(params)=>axios.put(`roles/${params.id}`,params) 
//获取权限列表
export let getRights=(params)=>axios.get(`rights/${params.type}`)
//删除角色权限
export let getDelRights=({roleId,rightId})=>axios.delete(`roles/${roleId}/rights/${rightId}`)
//修改角色权限
export let getEditRights=({rids,roleId})=>axios.post(`roles/${roleId}/rights`,{rids})
//获取左侧菜单数据
export let getMenus=(params)=>axios.get('menus')

//获取商品列表
export let getGoods=(params)=>axios.get('goods',{params})
//删除商品
export let getDelGoods=(params)=>axios.delete(`goods/${params}`)


//获取商品分类信息
export let getCategories=(params)=>axios.get('categories',{params})
//添加商品分类
export let getAddCategories=(params)=>axios.post('categories',params)
//编辑商品分类
export let getEditCategories=({cat_id,cat_name})=>axios.put(`categories/${cat_id}`,{cat_name})
//删除商品分类
export let getDelCategories=({cat_id})=>axios.delete(`categories/${cat_id}`)

//获取商品参数列表
export let getParams=(id,params)=>axios.get(`categories/${id}/attributes`,{params})
// 编辑参数属性
export let getEditParams=({id,attrId,attr_name,attr_sel,attr_vals})=>axios.put(`categories/${id}/attributes/${attrId}`,{attr_name,attr_sel,attr_vals})
//添加参数属性
export let getAddParams=({id,attr_name,attr_sel,attr_vals})=>axios.post(`categories/${id}/attributes`,{attr_name,attr_sel,attr_vals})
//删除参数
export let getDelParams=({cat_id,attr_id})=>axios.delete(`categories/${cat_id}/attributes/${attr_id}`)

//获取订单数据
export let getOrders=(params)=>axios.get('orders',{params})
//获取物流信息
export let getLogistics=({id})=>axios.get(`/kuaidi/${id}`)
//获取折线数据
export let getReports=(params)=>axios.get('reports/type/1')